﻿
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
         style="padding: 20px 30px 0 0;">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>基础信息</legend>
        </fieldset>
        <script type='text/html' template lay-done='layui.data.formdone(d.params);'>
            <input type='hidden' name='PID' value="{{ d.params.PID || '' }}" />
            <input type='hidden' name='BasicAttributes' id="BasicAttributes" value='{{ d.params.BasicAttributes || '' }}' />
        </script>
        <input type='hidden' name='Specs' />
        <input type='hidden' name='Params' />
        <div class='layui-form-item'>
            <label class='layui-form-label'>所属分类<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:705px;">
                <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"GoodsCategoryID_SelSource");'>
                    <!--<input type="hidden" id="GoodsCategoryID_SelSource" name="GoodsCategoryID_SelSource" value="{{ d.params.GoodsCategoryID_SelSource || '' }}" />
                <input type="hidden" id="GoodsCategoryID_SelSourceName" name="GoodsCategoryID_SelSourceName" value="{{ d.params.GoodsCategoryID_SelSourceName || '' }}" />-->
                    <select name="GoodsCategoryID_SelSource" id="GoodsCategoryID_SelSource" xm-select="GoodsCategoryID_SelSource" lay-verify='required' xm-select-radio="" xm-select-search xm-select-skin="default">
                        <option value=""></option>
                    </select>
                </script>
            </div>
            <!--<div class="layui-form-mid layui-word-aux">
            下方品牌、商品参数、销售信息根据商品分类改变
        </div>-->
        </div>
        <!--<div class='layui-form-item'>
        <label class='layui-form-label'>品牌<span style="color:red">*</span></label>
        <div class='layui-input-inline' style="width:705px;">
            <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"Brand");'>
            <select name='Brand' id='Brand' lay-search>
                <option value=""></option>
            </select>
            </script>
        </div>
    </div>-->
        <div class='layui-form-item'>
            <label class='layui-form-label'>名称<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:705px;">
                <script type='text/html' template>
                    <input type='text' name='Name' value='{{ d.params.Name || '' }}' lay-verify='required' placeholder='名称' autocomplete='off' class='layui-input'>
                </script>
            </div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>货号<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:705px;">
                <script type='text/html' template>
                    <input type='text' name='ArtNo' value='{{ d.params.ArtNo || '' }}' lay-verify='required' placeholder='货号' autocomplete='off' class='layui-input'>
                </script>
            </div>
        </div>

        <div class='layui-form-item'>
            <label class='layui-form-label'>副标题</label>
            <div class='layui-input-inline' style="width:705px;">
                <script type='text/html' template>
                    <input type='text' name='Title' value='{{ d.params.Title || '' }}' lay-verify='' placeholder='副标题' autocomplete='off' class='layui-input'>
                </script>
            </div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>检索关键字</label>
            <div class='layui-input-inline' style="width:705px;">
                <script type='text/html' template>
                    <input type='text' name='KeyWords' value='{{ d.params.KeyWords || '' }}' lay-verify='' placeholder='搜索关键字,如背包,旅行箱(逗号隔开)' autocomplete='off' class='layui-input'>
                </script>
            </div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>发货地</label>
            <div class='layui-input-inline' style="width:705px;">
                <script type='text/html' template>
                    <input type='text' name='PlaceOfDispatch' value='{{ d.params.PlaceOfDispatch || '' }}' lay-verify='' placeholder='发货地' autocomplete='off' class='layui-input'>
                </script>
            </div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>供应商<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:705px;">
                <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"SupplierID_SelSource");'>
                    <!--<select id="SupplierID_SelSource" name="SupplierID_SelSource" lay-verify='required' lay-search>
                    <option value=""></option>
                </select>-->

                    <select name="selectsupplier" id="selectsupplier" xm-select="selectsupplier" xm-select-radio="" lay-verify='required' xm-select-search xm-select-skin="default">
                        <!--<option value=""></option>-->
                    </select>
                    <input type="hidden" name="SupplierID_SelSource" id="SupplierID_SelSource" value='{{ d.params.SupplierID_SelSource || '' }}'>
                </script>
            </div>
        </div>

        <div class='layui-form-item'>
            <label class='layui-form-label'>商品介绍图<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:80%">
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="selectImg">选择图片</button> &nbsp;&nbsp;<span style="color:#c2c2c2">最多只能上传5张图片</span> <span id="imgsp">建议尺寸 750px * 750px</span>
                    <div class="layui-upload-list" id="divImgs"></div>
                    <script type='text/html' template lay-done='layui.data.setUploads(d.params);'>
                        <input type="hidden" name="Images" id="Images" value="{{ d.params.Images || '' }}">
                    </script>
                    <hr />
                </div>
            </div>
        </div>
        <!--<div class='layui-form-item'>
        <label class='layui-form-label'>价格<span style="color:red">*</span></label>
        <div class='layui-input-inline' style="width:705px;">
            <script type='text/html' template>
                <input type='text' name='Price' value='{{ d.params.Price || '' }}' lay-verify='required|number' placeholder='价格' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>-->

        <fieldset class="layui-elem-field layui-field-title">
            <legend>销售信息</legend>
        </fieldset>
        <div class='layui-form-item'>
            <div style="margin-bottom:10px;">
                <label class='layui-form-label'>规格<span style="color:red">*</span></label>
                <div class='layui-input-inline' style="width:200px;">
                    <script type='text/html' template>
                        <input type='text' style="width:174px;float:left;border-right:none;border-bottom-right-radius:0px;border-top-right-radius:0px;"
                               name='SpecMode' id="SpecMode" value='{{ d.params.SpecMode || '' }}' lay-verify='required' placeholder='多个规格用英文逗号,隔开' autocomplete='off' class='layui-input'>
                        <a class="layui-input" onclick="AddSpec();" style="width:26px;float:right;text-align:center;padding-left:0px;line-height:38px;cursor:pointer;border-left:none;border-bottom-left-radius:0px;border-top-left-radius:0px;font-size:0.8em;color:#c2c2c2">
                            <i class="layui-icon">&#xe624;</i>
                        </a>
                    </script>
                </div>
                <label class='layui-form-label'>重量(kg)<span style="color:red">*</span></label>
                <div class='layui-input-inline' style="width:120px;">
                    <script type='text/html' template>
                        <input type='text' name='Weight' id="Weight" value='{{ d.params.Weight || '' }}' lay-verify='required|number' placeholder='重量' autocomplete='off' class='layui-input'>
                    </script>
                </div>
                <label class='layui-form-label'>初始库存<span style="color:red">*</span></label>
                <div class='layui-input-inline' style="width:120px;">
                    <script type='text/html' template>
                        <input type='text' name='Stock' id="Stock" value='{{ d.params.Stock || '' }}' lay-verify='required|number' placeholder='初始库存' autocomplete='off' class='layui-input'>
                    </script>
                </div>
            </div>
        </div>
        <div class='layui-form-item'>
            <div style="margin-bottom:10px;">
                <!--<label class='layui-form-label'>配送方式<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:200px;">
                <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"DeliveMode");'>
                    <select name='DeliveMode' xm-select="DeliveMode" id='DeliveMode' lay-verify='required'>
                        <option value=""></option>
                    </select>
                </script>
            </div>-->
                <div id="divShip">
                    <label class='layui-form-label'>是否包邮<span style="color:red">*</span></label>
                    <div class='layui-input-inline' style="width:120px;">
                        <script type='text/html' template>
                            <select id="IsShipping_Sel" name="IsShipping_Sel" lay-verify='required' lay-filter="IsShip">
                                <option value='0' {{ d.params.IsShipping_Sel == '0' ? 'selected' : '' }}>不包邮</option>
                                <option value='1' {{ d.params.IsShipping_Sel == '1' ? 'selected' : '' }}>包邮</option>
                            </select>
                        </script>
                    </div>
                </div>
                <!--<label class='layui-form-label'>限购数量<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:120px;">
                <script type='text/html' template>
                    <input type='text' name='LimitNum' id="LimitNum" value='{{ d.params.LimitNum || '0' }}' lay-verify='required|number' placeholder='限购数量' autocomplete='off' class='layui-input'>
                </script>
            </div>
            <span style="color:green">默认0，表示无限制</span>-->
            </div>
        </div>
        <!--<div class='layui-form-item' id="divFreight">
            <label class='layui-form-label'>运费模板<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:350px;">
                <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"FreightID");'>
                    <select id="FreightID" name="FreightID" lay-search>
                        <option value=""></option>
                    </select>
                </script>
            </div>
            <span style="color:green">不包邮需要选择运费模板</span>
        </div>-->
        <!--<div class='layui-form-item'>
        <label class='layui-form-label'>限购区域</label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"LimitArea");'>-->
        <!--<select name="select2" xm-select="select2" xm-select-search xm-select-skin="default">
        <option value=""></option>
    </select>
    <input type="hidden" id="LimitArea" name="LimitArea" value="{{ d.params.LimitArea || '' }}" />-->
        <!--<select name="LimitArea" xm-select="LimitArea" xm-select-search xm-select-skin="default">
                    <option value=""></option>
                </select>
            </script>
        </div>
        <span style="color:green">所选区域内的收货地址才可下单</span>
    </div>-->
        <!--<div class='layui-form-item'>
        <label class='layui-form-label'>销售时间</label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template lay-done='layui.data.datedone(d.params);'>
                <input type='text' name='SaleTime' readonly='readonly' id='SaleTime' placeholder='开始时间 ~ 结束时间' autocomplete='off' class='layui-input'>
                <input type="hidden" id="SaleBegTime" name="SaleBegTime" value="{{ d.params.SaleBegTime || '' }}" />
                <input type="hidden" id="SaleEndTime" name="SaleEndTime" value="{{ d.params.SaleEndTime || '' }}" />
            </script>
        </div>
    </div>-->

        <fieldset class="layui-elem-field layui-field-title">
            <legend>
                商品-会员价格
            </legend>
        </fieldset>
        <div class='layui-form-item'>
            <label class='layui-form-label'>商品价格<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:100px;">
                <script type='text/html' template>
                    <input type='text' name='Price' id="Price" value='{{ d.params.Price || '' }}' lay-verify='required|number' placeholder='' autocomplete='off' class='layui-input'>
                </script>
            </div>
            <label class='layui-form-label'>结算价格<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:100px;">
                <script type='text/html' template>
                    <input type='text' name='Price1' id="Price1" value='{{ d.params.Price1 || '' }}' lay-verify='required|number' placeholder='' autocomplete='off' class='layui-input'>
                </script>
            </div>
            <span style="color:green">供应商结算价格</span>
        </div>
        <div id="divLevels">
            <!--<div class='layui-form-item'>
            <label class='layui-form-label'>钻石会员<span style="color:red">*</span></label>
            <div class='layui-input-inline' style="width:100px;">
                <input type='text' name='Level1' value='100' lay-verify='required|number' placeholder='' autocomplete='off' class='layui-input'>
            </div>
            <div class='layui-input-inline'>
                <input type="checkbox" id="IsShow" name="IsShow" lay-skin="switch" lay-text="展示|不展示">
            </div>
        </div>-->
        </div>

        <fieldset class="layui-elem-field layui-field-title">
            <legend>详细信息</legend>
        </fieldset>
        <div class='layui-form-item'>
            <label class='layui-form-label'>产品详情</label>
            <div class='layui-input-inline'>
                <script type='text/html' template lay-done='layui.data.getEdit(d.params);'>
                    <textarea placeholder="产品详情" name="Content_Edit" id="Content_Edit" class="editor">{{ d.params.Content_Edit || '' }}</textarea>
                </script>
            </div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>售后说明</label>
            <div class='layui-input-inline'>
                <script type='text/html' template lay-done='layui.data.getEdit1(d.params);'>
                    <textarea placeholder="售后保障" name="Aftersalest_Edit" id="Aftersalest_Edit" class="editor">{{ d.params.Aftersalest_Edit || '' }}</textarea>
                </script>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline">
                <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" value="确认" class="layui-btn">
            </div>
        </div>
    </div>
<style>
    .layui-upload-img {
        width: 100px;
        height: auto;
    }
    .input2{
        width: 20px;
        height:18px;
        position:absolute;
        bottom:0px;
        background-color:rgba(56, 56, 56, 0.82);
        border:rgba(56, 56, 56, 0.82);
        color:white;
        text-align:center;

    }
</style>
<script type="text/javascript">

    layui.use(['form', 'admin'], function () {
        var form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
        var admin = layui.admin;
        var $ = layui.$;

        form.on("select(IsShip)", function (data) {
            LoadFeight(data.value);
        })
      
        formSelects.config('GoodsCategoryID_SelSource', {
            keyName: 'Name',            //自定义返回数据中name的key, 默认 name
            keyVal: 'PID',            //自定义返回数据中value的key, 默认 value
            keyChildren: 'children',    //联动多选自定义children
        });


    });

    var Brand = "";
    layui.data.getSelSource = function (d, sourceName) {
        layui.use(['form', 'admin', 'formSelects'], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;
            var formSelects = layui.formSelects;

            Brand = d.Brand;
            if (sourceName == "GoodsCategoryID_SelSource") {
                admin.req({
                    url: layui.setter.APIUrl + '/shop/GoodsCategoryMgr/customerQuery', //实际使用请改成服务端真实接口
                    type: 'post',
                    done: function (res1) {
                     
                        formSelects.data('GoodsCategoryID_SelSource', 'local', {
                            arr: res1.Data
                        });
                        debugger
                        var dada = d.GoodsCategoryID_SelSource;
                      
                        layui.formSelects.value('GoodsCategoryID_SelSource', [d.GoodsCategoryID_SelSource]);
                    }
                });  
              
            }

            if (sourceName == "Brand") {
                admin.req({
                    url: layui.setter.APIUrl + '/shop/brandMgr/customerQuery', //实际使用请改成服务端真实接口
                    type: 'post',
                    done: function (res) {
                        layui.each(res.Data, function (index, eachdata) {
                            var strIsSel = '';
                            if (eachdata.Name == d.Brand)
                                strIsSel = "selected='selected'";
                            $("#Brand").append("<option value='" + eachdata.Name + "' " + strIsSel + ">" + eachdata.Name + "</option>");
                        });
                        form.render('select');
                    }
                });
            }
            if (sourceName == "SupplierID_SelSource") {
                //admin.req({
                //    url: layui.setter.APIUrl + '/shop/SupplierMgr/customerQuery', //实际使用请改成服务端真实接口
                //    type: 'post',
                //    done: function (res) {
                //        var html = "<option value=''></option>";
                //        layui.each(res.Data, function (index, eachdata) {
                //            var strIsSel = '';
                //            if (eachdata.PID == d.SupplierID_SelSource)
                //                strIsSel = "selected='selected'";
                //            html += "<option value='" + eachdata.PID + "' " + strIsSel + ">" + eachdata.Name + "</option>";
                //        });
                
                //        $("#selectsupplier").html(html);
                //        form.render('select1');
                //    }
                //});
             
                    admin.req({
                        url: layui.setter.APIUrl + '/shop/SupplierMgr/customerQuery', //实际使用请改成服务端真实接口
                        type: 'post',
                        done: function (res) {
                            layui.each(res.Data, function (index, eachdata) {
                                var strIsSel = '';
                                if (eachdata.PID == d.SupplierID_SelSource)
                                    strIsSel = "selected='selected'";
                                $("#selectsupplier").append("<option value='" + eachdata.Name + "' " + strIsSel + ">" + eachdata.Name + "</option>");
                            });
                            form.render('select');
                        }
                    });
                

                //formSelects.config('selectsupplier', {
                //    keyName: 'title',            //自定义返回数据中name的key, 默认 name
                //    keyVal: 'id',            //自定义返回数据中value的key, 默认 value
                //    keyChildren: 'children',    //联动多选自定义children
                //});

                //admin.req({
                //    url: layui.setter.APIUrl + '/shop/supplierMgr/customerQueryChildren2', //实际使用请改成服务端真实接口
                //    type: 'post',
                //    done: function (res) {
                //        layui.formSelects.data('selectsupplier', 'local', {
                //            arr: res.Data,
                //            linkage: true,
                //            linkageWidth: 120
                //        });
                //        var selID = d.SupplierID_SelSource;
                //        if (selID != "" && selID != undefined) {
                //            admin.req({
                //                url: layui.setter.APIUrl + '/shop/supplierMgr/GetModel?key=' + selID, //实际使用请改成服务端真实接口
                //                type: 'post',
                //                done: function (res) {
                //                    //如果有需要默认值的小伙伴请使用formSelects.
                //                    formSelects.value('selectsupplier', [res.Data.Area + "/" + res.Data.Level_Sel + res.Data.Area + "/" + selID]);
                //                }
                //            });
                //        }
                //    }
                //});
                //formSelects.on('selectsupplier', function (id, vals, val, isAdd, isDisabled) {
                //    if (isAdd == true) {
                //        if (val.value.indexOf("/") > 0 && ((val.value.split('/')).length - 1) >= 2) {  //多级选择时,第一级无法选中  供应商前两级都无法选中
                //            var value = val.value.split('/')[val.value.split('/').length - 1];
                //            $("#SupplierID_SelSource").val(value);  //实际选中效果为多个ID组合 ‘id1/id2/id3’,取最后一个
                //        } else {
                //            isAdd = false;
                //            return false;
                //        }
                //    } else {
                //        $("#SupplierID_SelSource").val("");
                //    }
                //});

            }
            if (sourceName == "DeliveMode") {
                formSelects.config('DeliveMode', {
                    keyName: 'Text',            //自定义返回数据中name的key, 默认 name
                    keyVal: 'PID',            //自定义返回数据中value的key, 默认 value
                });
                layui.formSelects.data('DeliveMode',
                    'local',
                    {
                        arr: [{ 'Text': '自提', 'PID': '0' }, { 'Text': '快递', 'PID': '1' }],//要把自己的这个节点去掉
                    });

                var selIDs = d.DeliveMode;
                if (selIDs != "" && selIDs != undefined) {
                    for (var i = 0; i < selIDs.split(',').length; i++) {
                        formSelects.value('DeliveMode', [selIDs.split(',')[i]], true);
                    }
                }

                formSelects.on('DeliveMode', function (id, vals, val, isAdd, isDisabled) {
                    //debugger;
                    $("#IsShipping_Sel").val(0);
                    $("#FreightID").val("");
                    form.render("select");
                    if (isAdd == true) {
                        if (val.value == 1) {
                            LoadShip(1, 0);
                        }
                    } else {
                        if (val.value == 1) {
                            LoadShip(0);
                        }
                    }
                });
                //formSelects.value('DeliveMode', []);
            }
            if (sourceName == "FreightID") {
                admin.req({
                    url: layui.setter.APIUrl + '/shop/FreightMgr/customerQuery', //实际使用请改成服务端真实接口
                    type: 'post',
                    done: function (res) {
                        var html = "<option value=''></option>";
                        layui.each(res.Data, function (index, eachdata) {
                            var strIsSel = '';
                            if (eachdata.PID == d.FreightID)
                                strIsSel = "selected='selected'";
                            html += "<option value='" + eachdata.PID + "' " + strIsSel + ">" + eachdata.RMK + "</option>";
                        });
                        $("#FreightID").html(html);
                        form.render('select');
                    }
                });
            }
            //if (sourceName == "LimitArea") {

            //    formSelects.config('LimitArea', {
            //        keyName: 'title',            //自定义返回数据中name的key, 默认 name
            //        keyVal: 'title',            //自定义返回数据中value的key, 默认 value
            //        keyChildren: 'children',    //联动多选自定义children
            //    });

            //    admin.req({
            //        url: layui.setter.APIUrl + '/shop/StoreareaMgr/customerQueryChildren', //实际使用请改成服务端真实接口
            //        type: 'post',
            //        done: function (res) {
            //            //debugger;
            //            layui.formSelects.data('LimitArea', 'local', {
            //                arr: res.Data,
            //                //linkage: true,
            //                //linkageWidth: 130
            //            });
            //            var selID = d.LimitArea;
            //            if (selID != "" && selID != undefined) {
            //                //selID += ",";
            //                //$.each(res.Data, function (i, d) {
            //                //    if (d.children != null) {
            //                //        $.each(res.Data[i].children, function (c, cd) {
            //                //            var area = res.Data[i].children[c].title + ",";
            //                //            if (selID.indexOf(area) >= 0) {
            //                //                var selvalue = res.Data[i].title + "/" + res.Data[i].children[c].title;
            //                //                formSelects.value('select2', [selvalue], true);
            //                //            }
            //                //        })
            //                //    }
            //                //})

            //                var areas = selID.split(',');
            //                $.each(areas, function (i, d) {
            //                    formSelects.value('LimitArea', [d], true);
            //                })
            //            }
            //        }
            //    });

            //    //收缩全部节点
            //    var isFirst = true;
            //    layui.formSelects.opened('LimitArea', function (id) {
            //        if (isFirst) {
            //            isFirst = false;
            //            $('[fs_id="LimitArea"]').find('.xm-cz i.icon-caidan').click();
            //        }
            //    });

            //    //formSelects.on('select2', function (id, vals, val, isAdd, isDisabled) {
            //    //    debugger;
            //    //    if (isAdd == true) {
            //    //        if (val.value.indexOf("/") > 0) {  //多级选择时,第一级无法选中
            //    //            var value = val.value.split('/')[val.value.split('/').length - 1];
            //    //            GetLimitArea(value);
            //    //        } else {
            //    //            isAdd = false;
            //    //            return false;
            //    //        }
            //    //    } else {
            //    //        var value = val.value.split('/')[val.value.split('/').length - 1];
            //    //        GetLimitArea(value);
            //    //    }
            //    //});
            //}
        });
    }

    function GetLimitArea(value) {
        var $ = layui.$;
        value = value + ",";

        //debugger;
        var LimitArea = $("#LimitArea").val();
        if (LimitArea == "" || LimitArea == null) {
            LimitArea = value;
        } else {
            LimitArea +=",";
            if (LimitArea.indexOf(value) >= 0) {
                LimitArea = LimitArea.replace(value, "");
            } else {
                LimitArea += value;
            }
        }
        if (LimitArea != "") {
            LimitArea = LimitArea.substring(0, LimitArea.length - 1);
        }
        $("#LimitArea").val(LimitArea);
    }

    function LoadCate(cateid) {
      
        layui.use(['form', 'admin', 'formSelects'], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;

            var formSelects = layui.formSelects;

         
            //formSelects.config('select1', {
            //    keyName: 'title',            //自定义返回数据中name的key, 默认 name
            //    keyVal: 'id',            //自定义返回数据中value的key, 默认 value
            //    keyChildren: 'children',    //联动多选自定义children
            //});

            //admin.req({
            //    url: layui.setter.APIUrl + '/shop/GoodsCategoryMgr/customerQueryChildren', //实际使用请改成服务端真实接口
            //    type: 'post',
            //    done: function (res) {
            //        layui.formSelects.data('select1', 'local', {
            //            arr: res.Data,
            //            linkage: true,
            //            linkageWidth: 130
            //        });
            //        var selID = cateid;
            //        if (selID != "" && selID != undefined) {
            //            admin.req({
            //                url: layui.setter.APIUrl + '/shop/GoodsCategoryMgr/GetAllCate?cateid=' + selID, //实际使用请改成服务端真实接口
            //                type: 'post',
            //                done: function (res) {
            //                    //如果有需要默认值的小伙伴请使用formSelects.value
            //                    formSelects.value('select1', [res.ResultInfo]);
            //                }
            //            });
            //        }
            //    }
            //});

            //formSelects.on('select1', function (id, vals, val, isAdd, isDisabled) {
            //    if (isAdd == true) {
            //        if (val.value.indexOf("/") > 0) {  //多级选择时,第一级无法选中
            //            var value = val.value.split('/')[val.value.split('/').length - 1];
            //            $("#GoodsCategoryID_SelSource").val(value);  //实际选中效果为多个ID组合 ‘id1/id2/id3’,取最后一个
            //            //SelCateDone(value, null, null);
            //        } else {
            //            isAdd = false;
            //            return false;
            //        }
            //    } else {
            //        $("#GoodsCategoryID_SelSource").val("");
            //        //SelCateDone("", null, null);
            //    }
            //});
        });
    }

    function AddSpec() {
        var $ = layui.$;

        layer.prompt({ title: '请输入规格', formType: 0 }, function (text, index) {
            layer.close(index);
            
            var specStr = $("#SpecMode").val();
            if (specStr == null || specStr == "") {
                specStr = text;
            } else {
                specStr += "," + text;
            }
            $("#SpecMode").val(specStr);
        });
    }

    var ImgNum = 0;
    var Images = [];
    layui.data.setUploads = function (d) {
        layui.use(['jquery', 'upload', 'admin'], function () {
            window.jQuery = window.$ = layui.jquery;
            upload = layui.upload,
                admin = layui.admin;
            //多图上传
            var uploadInst = upload.render({
                elem: '#selectImg'
                , url: '/WebAPI/file/uploadImgNew?access_token=' + layui.data('layuiAdmin').access_token
                , acceptMime: 'image/*'
                , multiple: true
                , number: 5
                , done: function (res) {
                    if (res.ResultCode == 0) {
                        //debugger;
                        if (Images.length >= 5) {
                            return layer.msg("最多上传五张图片");
                        }
                        addImg(res.Data);
                        layer.msg('上传成功');
                    } else {
                        layer.msg(res.ResultInfo);
                    }
                }
            });
            var pics = d.Images;
            if (pics != "" && pics != null && pics != 'null') {
                //var s = pics.replace(/&quot;/g, '"');
                var strs = JSON.parse(pics);
                for (var i = 0; i < strs.length; i++) {
                    var str = strs[i];
                    if (str != "") {
                        addImg({ name: str, path: layui.setter.ImgPath + str });
                    }
                }
            }
        })
    }
    function addImg(src) {
        var div = "divimg" + ImgNum;
        var img = "Img" + ImgNum;
        var html = "    <div style=\"line-height:100px;float:left\" id='" + div + "'> " +
                           " <a style=\"float:right;line-height:10px;background-color:#ff0000;font-size:24px;color:white;border-top:3px solid #ff0000\" onclick=\"deletp(" + ImgNum + ")\">×</a> " +
                           " <img id='" + img + "' src=\"" + src.path + "\"   alt=\"\" class=\"layui-upload-img\">" +
                           " <input type='text' class='input2' value='" + (ImgNum + 1) + "' oninput=\"changeXh('" + ImgNum + "', this.value)\" />" +
                       "</div>";
        $('#divImgs').append(html);

        var image = {};
        image["src"] = src.name;
        image["xh"] = ImgNum;
        Images.push(image);

        var strs = [];
        $.each(Images, function (i, d) {
            var str = d.src;
            strs.push(str);
        })

        $("#Images").val(JSON.stringify(strs));
        ImgNum++;
    }
    //删除图片
    function deletp(num) {
        debugger
        var div = "divimg" + num;
        for (var i = 0; i < Images.length; i++) {
            if ((layui.setter.ImgPath + Images[i].src) == $("#Img" + num + "").attr("src")) {
                Images.splice(i, 1);
            }
        }
        var divImg = document.getElementById(div);
        divImg.parentNode.removeChild(divImg);

        var strs = [];
        $.each(Images, function (i, d) {
            var str = d.src;
            strs.push(str);
        })
        $("#Images").val(JSON.stringify(Images));
    }
    function changeXh(num, value) {
        for (var i = 0; i < Images.length; i++) {
            if ((layui.setter.ImgPath + Images[i].src) == $("#Img" + num + "").attr("src")) {
                Images[i].xh = value;
            }
        }
        //debugger;
        Images.sort(compare);

        var strs = [];
        $.each(Images, function (i, d) {
            var str = d.src;
            strs.push(str);
        })
        $("#Images").val(JSON.stringify(strs));
    }
    function compare(a, b) {
        return a.xh - b.xh;
    };


    layui.data.datedone = function (d) {
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            var $ = layui.$;

            var value = "";
            if (d.SaleBegTime != "" && d.SaleBegTime != null) {
                value = d.SaleBegTime + " ~ " + d.SaleEndTime;
            }
            laydate.render({
                elem: '#SaleTime',
                type: 'datetime',
                range: '~', //指定元素
                value: value,
                min: 0,
                done: function (value, date, endDate) {
                    if (value != "") {
                        var times = value.split('~');
                        $("#SaleBegTime").val(times[0].trim());
                        $("#SaleEndTime").val(times[1].trim());
                    } else {
                        $("#SaleBegTime").val("");
                        $("#SaleEndTime").val("");
                    }
                    $("#SaleTime").val(value);
                }
            });
        });
    }

    layui.data.getEdit = function (d) {
        layui.use(['kindeditor', 'kindeditor_lang'], function () {
            //debugger
            var KindEditor = layui.kindeditor;
            //初始化编辑器
            var editor;
            editor = KindEditor.create('.editor', {
                basePath: layui.setter.base + 'lib/extend/editor/',
                width: '900px',
                height: '370px',
                resizeType: 1,
                imageSizeLimit: '10MB',
                uploadJson: '/WebAPI/file/editorUploadImg?folder=shop_goods_base&access_token=' + layui.data('layuiAdmin').access_token,
                fileManagerJson: '/WebAPI/file/ManagerFile?folder=shop_goods_base&access_token=' + layui.data('layuiAdmin').access_token,
                allowFileManager: true,
                afterBlur: function () { this.sync(); }
            });
            //editor.html(d.Content_Edit);
        })
    }

    layui.data.getEdit1 = function (d) {
        //debugger
        layui.use(['kindeditor', 'kindeditor_lang'], function () {
            //debugger
            var KindEditor = layui.kindeditor;
            //初始化编辑器
            var editor;
            editor = KindEditor.create('.editor', {
                basePath: layui.setter.base + 'lib/extend/editor/',
                width: '900px',
                height: '370px',
                resizeType: 1,
                imageSizeLimit: '10MB',
                uploadJson: '/WebAPI/file/editorUploadImg?folder=shop_goods_base&access_token=' + layui.data('layuiAdmin').access_token,
                fileManagerJson: '/WebAPI/file/ManagerFile?folder=shop_goods_base&access_token=' + layui.data('layuiAdmin').access_token,
                allowFileManager: true,
                afterBlur: function () { this.sync(); }
            });
        })
    }



    var StockNum = 1;
    var Stocks = [];
    var MenmberLevels = [];
    layui.data.formdone = function (d) {
        //debugger;
        LoadMemberPrice(d.PID);

        //是否包邮 显示运费模板选项
        if (d.IsShipping_Sel == "" || d.IsShipping_Sel == null) {
            LoadFeight(0);
        } else {
            LoadFeight(d.IsShipping_Sel);
        }
        if (d.DeliveMode != "" && d.DeliveMode != null && d.DeliveMode.indexOf("1") >= 0) {
            LoadShip(1, d.IsShipping_Sel);
        } else {
            LoadShip(0);
        }
    }



    //加载会员价格
    function LoadMemberPrice(GoodID) {
        var $ = layui.$;
        var form = layui.form;
        var admin = layui.admin;

        admin.req({
            url: layui.setter.APIUrl + '/shop/Goods_memberpriceMgr/getLevels?GoodID=' + GoodID, //实际使用请改成服务端真实接口
            type: 'post',
            done: function (res) {
                var data = res.Data;
                MenmberLevels = data;
                var html = "";
                $.each(data, function (i, d) {
                    var levelstr = d.LevelStr;
                    var levelid = "Level" + d.Level;
                    var price = d.Price;
                    if (price == null || price == 0) {
                        price = "";
                    }
                    var showid = "IsShow" + d.Level;
                    var checked = "";
                    if (d.IsShow == 1) {
                        checked = "checked";
                    }
                    html += "" +
                        "<div class='layui-form-item'>" +
                        "  <label class='layui-form-label'>" + levelstr + "<span style=\"color:red\">*</span></label>" +
                        "  <div class='layui-input-inline' style=\"width:100px;\">" +
                        "          <input type='text' id='" + levelid + "' value='" + price + "' lay-verify='required|number' placeholder='' autocomplete='off' class='layui-input'>" +
                        "  </div>" +
                        "  <div class='layui-input-inline'>" +
                        "      <input type='checkbox' id='" + showid + "' " + checked + " lay-skin='switch' lay-text=\"展示|不展示\">" +
                        "  </div>" +
                        "</div>";
                });
                $("#divLevels").html(html);
                form.render();
            }
        });
    }
    //获取会员价格
    function GetMemberPrice() {
        var $ = layui.$;
        for (var i = 0; i < MenmberLevels.length; i++) {
            var levelid = "Level" + MenmberLevels[i].Level;
            var showid = "IsShow" + MenmberLevels[i].Level;
            var price = $("#" + levelid + "").val();
            MenmberLevels[i].IsShow = 0;
            if ($('#' + showid).is(':checked')) {
                MenmberLevels[i].IsShow = 1;
            }
            MenmberLevels[i].Price = price;
        }
        var res = JSON.stringify(MenmberLevels);
        return res;
    }


    function LoadShip(iskd, isship) {
        if (iskd == 1) {
            //$("#divShip").show();
            if (isship == 1) {
                LoadFeight(1);
            } else {
                LoadFeight(0);
            }
        } else {
            //$("#divShip").hide();
            LoadFeight(1);
        }
    }

    function LoadFeight(IsShip) {
        if (IsShip == 0) {
            $("#divFreight").show();
        } else {
            $("#divFreight").hide();
        }
    }


    //function Return() {
    //    location.href = "/Admin/start/index.html#" + "/shop/shop_Goods_Base/Index";
    //}
</script>